package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.common.SortEnum;
import com.baomidou.springboot.entity.Client;
import com.baomidou.springboot.mapper.ClientMapper;
import com.baomidou.springboot.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 人才招聘 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class ClientServiceImpl implements ClientService {

    @Autowired
    private ClientMapper clientMapper;

    @Override
    public void save(Client client) {
        client.setCreateDate(new Date());
        clientMapper.insert(client);
    }

    @Override
    public void delete(String id) {
        clientMapper.deleteById(id);
    }

    @Override
    public Client edit(String id) {
        return clientMapper.selectById(id);
    }

    @Override
    public void update(Client client) {
        client.setModifyDate(new Date());
        clientMapper.updateById(client);
    }

    @Override
    public Client view(String id) {
        return clientMapper.selectById(id);
    }

    @Override
    public Page<Client> list(Page<Client> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Client> clientList = clientMapper.findByDateDesc(page, search);
        page.setRecords(clientList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        clientMapper.deleteBatchIds(ids);
    }

    @Override
    public List<Client> findBySort(SortEnum sortEnum) {
        return clientMapper.findBySort(sortEnum.name());
    }
}
